<template>
    <div>
    <div  id="main" style="width: 900px;height:600px;">

    </div>
    </div>
</template>

<script>
    import echarts from 'echarts'
    export default {
        name: "PayMoneyECharts",
        data(){
            return{
                myChart:'',
                data:[10,30,20,18,40,32]
            }
        },
        mounted() {
                this.$nextTick(()=>{
                    this.echartsData()
                    this.EChcrts()
                })
        },
        methods:{
            //向后台请求数据
           async echartsData(){
                const  result =await this.$http.get('echartsData')


               if(1!==result.data.code){
                   return this.$message.error('获取数据失败！')
               }
               this.data=result.data.data

            },
            EChcrts(){
                this. myChart = echarts.init(document.getElementById('main'));
                let option = {
                    title: {
                        text: '图表展示'
                    },
                    tooltip: {},
                    legend: {
                        data:['完成数量']
                    },
                    xAxis: {
                        data: ["轴承","轮对","磁粉探伤","磨合实验","注油机","轴颈测量"]
                    },
                    yAxis: {},
                    series: [{
                        name: '完成数量',
                        type: 'bar',
                        data: this.data
                    }]
                };
                this.myChart.setOption(option);
            }


        }
    }
</script>

<style lang="less" scoped>

</style>